﻿@{
    Layout = "~/Views/Shared/_Layout.cshtml";
    ViewBag.Title = "应用管理";
}

<div id="page-header" class="clearfix">
    <div class="page-header">
        <h2>应用管理</h2>
        <span class="txt">可以增删查改所有的应用</span>
    </div>
</div>

<div class="panel panel-default toggle panelMove panelClose panelRefresh">
    <!-- Start .panel -->
    <div class="panel-heading">
        <h4 class="panel-title">查询条件</h4>
    </div>
    <div class="panel-body pt0 pb0">
        <form class="form-horizontal group-border">
            @Html.AntiForgeryToken()
            <div class="form-group col-lg-6 col-md-6">
                <label class="col-lg-3 col-md-3 control-label" for="">应用名称</label>
                <div class="col-lg-9 col-md-9">
                    <input id="txtApplicationName" type="text" class="form-control" name="default">
                </div>
            </div>
        </form>
    </div>
    <div class="panel-footer">
        <a class="btn btn-primary button-floatRight" href="@Url.Action("Create")">添加</a>
        <button id="btnReset" type="reset" class="btn btn-danger button-floatRight">重置</button>
        <button id="btnQuery" type="submit" class="btn btn-primary button-floatRight">查询</button>
    </div>
</div>

<div class="panel panel-default toggle panelMove panelClose panelRefresh">
    <div class="panel-heading">
        <h4 class="panel-title">查询结果</h4>
    </div>
    <div class="panel-body">
        <table id="ApplicationTable" class="table table-striped table-hover dt-responsive nowrap" cellspacing="0" width="100%"></table>
    </div>
</div>
<script>
    $(document).ready(function () {
        Applications.Search();

        $("#btnQuery").click(function () {
            Applications.Search();
        });

        $("#btnReset").click(function () {
            $("form").each(function () {
                this.reset();
            });
        });
        $("#btnAdd").click(function () {
            Applications.Add(this);
        });
    });

    var Applications = {
        Search: function () {
            $("#ApplicationTable").mainToolDataTable({
                "ajax": {
                    url: '@Url.Action("PageApplications")',
                    type: 'POST',
                    data: { filter: { Name: $("#txtApplicationName").val() } }
                },
                "columns": [
                    { "data": "Name", "title": "应用名称" },
                    {
                        title: "操作",
                        orderable: false,
                        data: "Id",
                        style: "min-width:190px;",
                        render: function (data, type, row) {
                            return "<a href='@Url.Action("Edit")?id=" + data + "'>修改</a>&nbsp;&nbsp;" +
                                   "<a href='javascript:void(0)' data-href='@Url.Action("Delete")?id=" + data + "' onclick='Applications.Delete(this)'>删除</a>";
                        }
                    }
                ]
            });
        },
        Delete: function (e) {
            $.mainTool.confirm("是否删除该信息？", function (result) {
                $.ajax({
                    type: 'post',
                    url: $(e).attr("data-href"),
                    data: { '__RequestVerificationToken': $("input[name='__RequestVerificationToken']").val() },
                    dataType: "json",
                    success: function (data) {
                        Applications.Search();
                    },
                    error: function (e) {
                        alert(e.responseText);
                    }
                });
            });
        }
    };
</script>
